/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.network.topo.route;

import java.awt.BorderLayout;
import java.awt.Color;
import java.io.IOException;

import javax.swing.JSplitPane;

import twaver.AlarmSeverity;
import twaver.Link;
import twaver.TDataBox;
import twaver.TWaverConst;
import twaver.Node;
import twaver.network.TNetwork;
import demo.DemoPane;

public class RouteTraceDemo extends DemoPane {
    TDataBox box = new TDataBox();
    TNetwork network1 = new TNetwork(box);
    TNetwork network2 = new TNetwork(box);
    
    public RouteTraceDemo() {
        initRoute1();
        initRoute2();
        JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, network1, network2);
        split.setDividerLocation(300);
        this.add(split, BorderLayout.CENTER);   
    }

    private void initRoute1() {
        int count = 8;
        for (int i = 0; i < count; i++) {
            Node node = new Node("Node" + i);
            node.setName(node.getID().toString());
            if (i == 0 || i == count - 1) {
                node.setImage("/demo/network/topo/route/pathNode1.png");
                node.setLocation(20 + i * 100, 56);
            } else {
                node.setImage("/demo/network/topo/route/pathNode2.png");
                node.setLocation(20 + i * 100, 60);
            }
            if (i % 2 == 1) {
                node.setLocation(node.getLocation().x, node.getLocation().y + 20);
            }
            if (i == 5) {
                node.getAlarmState().addNewAlarm(AlarmSeverity.MINOR);
            }
            box.addElement(node);
        }
        for (int i = 1; i < count; i++) {
            Node fromNode = (Node) box.getElementByID("Node" + (i - 1));
            Node toNode = (Node) box.getElementByID("Node" + i);
            Link link = new Link("Link" + i, fromNode, toNode);
            link.setLinkType(TWaverConst.LINK_TYPE_FLEXIONAL);
            link.putLinkWidth(6);
            link.putLinkColor(Color.cyan.darker());
            if (i == 2) {
                link.putLinkStyle(TWaverConst.LINK_STYLE_DASH);
                link.getAlarmState().addNewAlarm(AlarmSeverity.CRITICAL);
            }else{
            	link.putLink3D(true);
            }
            box.addElement(link);
        }
    }

    private void initRoute2() {
        try {
            box.parse("/demo/network/topo/route/path.xml");
        }
        catch (IOException ex) {
            ex.printStackTrace();
        }
    }

}